#ifndef COMMONINFOMODULE_H
#define COMMONINFOMODULE_H

#include <QObject>
#include <algorithm>
#include <QtCore/QtCore>
#include <QtNetwork/QtNetwork>
#include <QtDBus/QtDBus>
#include <stdio.h>
#include <QRegularExpression>
#include <QJsonObject>
#include <QJsonDocument>
#include "ConfModule.h"
#include "CommonInfoCollection.h"
#include "BaseModule.h"

class CommonInfoModule : public BaseModule
{
    Q_OBJECT
private:
    /**
     * @brief 主板信息请求头键
     * 
     */
    static constexpr const char* s_mainBoardSerialNumberKey = "X-Machine-Code";
    /**
     * @brief 网卡mac请求头键
     * 
     */
    static constexpr const char* s_networkMacAddressKey = "X-Machine-Mac";
    /**
     * @brief 处理器类型请求头键
     * 
     */
    static constexpr const char* s_processorModelKey = "X-Machine-Cpu";
    /**
     * @brief 显卡类型请求头键
     * 
     */
    static constexpr const char* s_graphicsCardModelKey = "X-Graphics-Card-Type";
    /**
     * @brief 系统版本请求头键
     * 
     */
    static constexpr const char* s_systemVersionKey = "X-Os-Version";
    /**
     * @brief 系统服务序列号请求头键
     * 
     */
    static constexpr const char* s_systemSerialNumberKey = "X-Service-Serial-No";
    /**
     * @brief 网卡类型请求头键
     * 
     */
    static constexpr const char* s_networkTypeKey = "X-Network-Type";
    /**
     * @brief 硬盘序列号请求头键
     * 
     */
    static constexpr const char* s_hardDiskSerialNumberKey = "X-Hard-Disk-Serial-No";
    /**
     * @brief 内核版本请求头键
     * 
     */
    static constexpr const char* s_kernelVersionKey = "X-Kernel-Version";
    /**
     * @brief 系统uuid
     * 
     */
    static constexpr const char* s_systemUuidKey = "X-System-UUID";
    /**
     * @brief 厂商名
     *
     */
    static constexpr const char* s_systemManufacturerKey = "X-System-Manufacturer";
    /**
     * @brief 产品名
     *
     */
    static constexpr const char* s_systemProductNameKey = "X-System-Product-Name";
    /**
     * @brief machineId
     * 
     */
    static constexpr const char* s_machineIdKey = "X-Uid";
    /**
     * @brief 模块名
     * 
     */
    static constexpr const char *s_moduleName = "CommonInfoModule";
    /**
     * @brief 定时器间隔配置键
     * 
     */
    static constexpr const char *s_pollingIntervalKey = "PollingInterval";
    /**
     * @brief 定时器
     * 
     */
    QTimer *m_timer;
    /**
     * @brief 单例对象
     * 
     */
    static QScopedPointer<CommonInfoModule> ms_instance;
    /**
     * @brief 打印基础信息
     * 
     * @param commonInfo 基础信息
     */
    void printInfo(const CommonInfo &commonInfo);
    /**
     * @brief 生成适合存储的基础信息字符串
     * 
     * @param commonInfo 基础信息
     * @return QString 基础信息字符串
     */
    QString packageInfo(const CommonInfo &commonInfo);
    /**
     * @brief Construct a new Common Info Module object
     * 
     * @param parent 
     */
    explicit CommonInfoModule(QObject *parent = nullptr);
public:
    /**
     * @brief Destroy the Common Info Module object
     * 
     */
    virtual ~CommonInfoModule();
    /**
     * @brief singleton function
     * 
     * @return CommonInfoModule* 单例结果
     */
    static CommonInfoModule *instance(void);
    /**
     * @brief 获取公共信息
     * 
     */
    void dealInfo();
public slots:
    virtual void updateProperty(const QJsonObject &conf, const QJsonObject &defaultConf);
    void setTimePollingInterval(qlonglong sec);
signals:
    /**
     * @brief 发送公共信息
     * 
     * @param info 公共信息
     */
    void sendInfo(const QString &info);


    //	property
private:
    Q_PROPERTY(qlonglong pollingInterval READ pollingInterval WRITE setPollingInterval NOTIFY pollingIntervalChanged)
    qlonglong m_pollingInterval;
public:
    qlonglong pollingInterval() const
    {
        return m_pollingInterval;
    }
public slots:
    void setPollingInterval(qlonglong pollingInterval)
    {
        if (m_pollingInterval == pollingInterval)
            return;

        m_pollingInterval = pollingInterval;
        emit pollingIntervalChanged(m_pollingInterval);
    }
signals:
    void pollingIntervalChanged(qlonglong pollingInterval);
};

#endif // COMMONINFOCOLLECTION_H
